package edu.luc.example;
import org.junit.After;
import org.junit.Test;
import org.junit.Before;

import junit.framework.TestCase;

public class CalculatorTest extends TestCase
{
	
	private Calculator calc;
	
	@Before
	public void setUp()
	{
		calc = new Calculator();
	}
	
	@After
	public void tearDown()
	{
		calc.clear();
		calc = null;
	}
	
	@Test
	public void testAdd()
	{
		calc.add(12);
		calc.add(2);
		assertEquals(14.0, calc.getResult());
		calc.clear();
		
		calc.add(-12);
		calc.add(2);
		assertEquals(-10.0, calc.getResult());
		calc.clear();
	}
	
	@Test
	public void testSubtract()
	{
		calc.add(10);
		calc.subtract(5);
		assertEquals(5.0, calc.getResult());
		calc.clear();
		
		calc.add(-10);
		calc.subtract(5);
		assertEquals(-15.0, calc.getResult());
		calc.clear();
		
		calc.add(-10);
		calc.subtract(-5);
		assertEquals(-5.0, calc.getResult());
		calc.clear();
	}
	
	@Test
	public void testMultiply()
	{
		calc.multiply(5);
		assertEquals(0.0, calc.getResult());
		calc.clear();
		
		calc.add(10);
		calc.multiply(1);
		assertEquals(10.0, calc.getResult());
		calc.clear();
		
		calc.add(-5);
		calc.multiply(-5);
		assertEquals(25.0, calc.getResult());
	}
	
	@Test
	public void testDivide()
	{
		calc.add(10);
		calc.divide(2);
		assertEquals(5.0, calc.getResult());
		calc.clear();
		
		calc.divide(0.0);
		assertEquals(0.0, calc.getResult());		
	}
	
	@Test
	public void testSquare()
	{
		calc.square(6);
		assertEquals(36.0, calc.getResult());
		calc.clear();
		
		calc.square(-5.0);
		assertEquals(25.0, calc.getResult());		
	}
	
	@Test
	public void testSquareRoot()
	{
		calc.squareRoot(-36.0);
		assertEquals(0.0, calc.getResult());
		calc.clear();
		
		calc.squareRoot(36.0);
		assertEquals(6.0, calc.getResult());
	}
}
